$.extend({
    http: function(requestURL, ajaxData, ajaxConf, callback) {
        return new Promise(function(resolve, reject) {
            var serverURL = requestURL.indexOf('http') > -1 ? requestURL : $.BASE_URL + requestURL;
            !ajaxConf.notShowLoad && $.load({ show: true });

            $.ajax({
                url: serverURL, // 请求路径
                type: ajaxConf.type || 'GET',
                async: ajaxConf.async || true,                  // 是否异步
                data: ajaxData || {},
                dataType: ajaxConf.dataType || 'json',          // 服务器返回的数据类型
                timeout: ajaxConf.timeout || 17000,              // 请求超时时间
                contentType: ajaxData instanceof FormData ? false : ajaxConf.contentType || 'application/json;charset=utf-8',
                processData: ajaxData instanceof FormData ? false : true,
                headers: {},
                success: function(res) {
                    if(typeof(callback) === 'function') callback(res);
                    resolve(res);
                    !ajaxConf.notShowLoad && $.load({ show: false });
                },
                error: function(err) {
                    if(typeof(callback) === 'function') callback(err);
                    reject(err);
                    !ajaxConf.notShowLoad && $.load({ show: false });
                }
            });
        });
    },
    BASE_URL: 'http://198.23.196.116:5000',
    getUrlParams: function (name) {
        var params = window.location.search.substring(1).split('&');
        for (var i = 0; i < params.length; i++) {
            var param = params[i].split('=');
            if (param[0] === name) {
                return decodeURIComponent(param[1]);
            }
        }
        return null;
    },
    detectDeviceType: function () {
        var deviceAgent = window.navigator.userAgent;
        var result = true;
        switch (result) {
            case deviceAgent.search(/Android/i) > -1:
                result = 'android';
                break;
            case deviceAgent.search(/iPhone|iPad|iPod/i) > -1:
                result = 'ios';
                break;
            case deviceAgent.search(/Windows|Macintosh|Linux|X11/i) > -1:
                result = 'pc';
                break;
            default:
                result = 'others';
        }
        return result;
    }
});